home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
276-300
/
285
/
liner
/
source
/
clip.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-14
|
5KB
|
208 lines
/*Clipboard I/O routines*/
#define WCLIP_FIRST_WRITE 0
#define WCLIP_CONT_WRITE 1
#define WCLIP_LAST_WRITE 2
SetupClipboard() /*Setup the clipboard device*/
{
if(OpenDevice("clipboard.device",0,&ClipboardIO,0)!=0)
{
TitleError("Can't open clipboard!\n");
Delay(500); /*Pause for 5 seconds; get the user's attention*/
CloseWindow(Window);
CloseScreen(Screen);
exit();
}
clipboardMsgPort.mp_Node.ln_Type=NT_MSGPORT;
clipboardMsgPort.mp_Flags=0;
clipboardMsgPort.mp_SigBit=AllocSignal(-1);
clipboardMsgPort.mp_SigTask=(struct Task *)FindTask((char *)NULL);
AddPort(&clipboardMsgPort);
ClipboardIO.io_Message.mn_ReplyPort=(struct MsgPort *)&clipboardMsgPort;
}
WriteInvsTextToClip(StartLoc,Chars,String)
int StartLoc,Chars; /*Write a highlighted text block to clipboard*/
char *String;
{
char WorkString[80];
strcpy(WorkString,"");
strcpy(WorkString,&String[StartLoc]);
WorkString[Chars]=NULL;
WriteStringClip(WorkString);
}
WriteStringClip(string) /*Write a string to the Clipboard*/
char *string;
{
int len;
/*Write the data, in IFF form*/
WriteClip(&ClipboardIO,"FORM",4,WCLIP_FIRST_WRITE);
len=strlen(string)+12;
WriteClip(&ClipboardIO,&len,4,WCLIP_CONT_WRITE);
WriteClip(&ClipboardIO,"FTXT",4,WCLIP_CONT_WRITE);
WriteClip(&ClipboardIO,"CHRS",4,WCLIP_CONT_WRITE);
len=strlen(string);
WriteClip(&ClipboardIO,&len,4,WCLIP_CONT_WRITE);
WriteClip(&ClipboardIO,string,len,WCLIP_LAST_WRITE);
}
WriteClip(ioreq,buf,bufsiz,whichone) /*Writes a clip to the clipboard*/
register struct IOClipReq *ioreq;
char *buf;
int bufsiz;
int whichone;
{
if(whichone==WCLIP_FIRST_WRITE) /*First time*/
{
ioreq->io_Offset=0;
ioreq->io_ClipID=0;
}
ioreq->io_Command=CMD_WRITE;
ioreq->io_Data=buf;
ioreq->io_Length=bufsiz;
DoIO(ioreq);
if(whichone==WCLIP_LAST_WRITE) /*Last time, tell clipboard to make the*/
{ /*data available to the system*/
ioreq->io_Command=CMD_UPDATE;
DoIO(ioreq);
}
}
ShutDownClipboard()
{
RemPort(&clipboardMsgPort);
CloseDevice(&ClipboardIO);
}
ReadItemString(Start,Len,string)
int Start,Len; /*Read a string from the clipboard and put it into*/
char *string; /*the specified string*/
{
char WorkString[80];
char TmpString[80];
strcpy(TmpString,"");
strcpy(WorkString,"");
ReadString(WorkString,79);
strcpy(TmpString,string);
TmpString[Start]=NULL;
strcat(TmpString,WorkString);
strncat(TmpString,&string[Start],79-strlen(TmpString));
TmpString[79]=NULL;
strcpy(string,TmpString);
}
ReadString(string,len) /*Read a string from the Clipboard*/
char *string;
int len;
{
char WorkingString[80];
int length;
strcpy(WorkingString,"");
length=ReadClip(&ClipboardIO,WorkingString,79);
if(!strncmp("FTXT",WorkingString,4))
return(FALSE);
strcpy(string,&WorkingString[20]);
string[20+len]=NULL;
return(TRUE);
}
ReadClip(ioreq,buf,bufsiz)
register struct IOClipReq *ioreq;
char *buf; /*Read data from the Clipboard*/
int bufsiz;
{
int length;
ioreq->io_Command=CMD_READ;
ioreq->io_Data=buf;
ioreq->io_Length=bufsiz-1;
ioreq->io_Offset=0;
ioreq->io_ClipID=0;
DoIO(ioreq);
length=ioreq->io_Actual;
*(buf+length)='\0';
if(ioreq->io_Actual <(bufsiz-1))
{
ioreq->io_Command=CMD_READ;
ioreq->io_Length=1;
ioreq->io_Data=NULL;
DoIO(ioreq);
}
return(length);
}
SnagBlock(Source,Last) /*Copy block of lines into clip (non-clipboard)*/
struct LineItem *Source,*Last;
{
struct LineItem *Dest;
ClipStart=ClipEnd=(struct LineItem *)NULL;
ClipStart=ClipEnd=Dest=(struct LineItem *)InsertItem(NULL,NULL);
Dest->Level=Source->Level;
strcpy(Dest->Text,Source->Text);
Source=(struct LineItem *)Source->NextItem;
while(Source != Last->NextItem)
{
ClipEnd=Dest=(struct LineItem *)InsertItem(NULL,Dest);
Dest->Level=Source->Level;
strcpy(Dest->Text,Source->Text);
Source=(struct LineItem *)Source->NextItem;
}
}
AddBlock(Start) /*Insert a SnagBlocked item list into the main list*/
struct LineItem *Start; /*starting at Start*/
{
struct LineItem *Item,*Dest;
int TempX,TempY;
UBYTE OrigLevel;
Item=(struct LineItem *)ClipStart;
Dest=(struct LineItem *)InsertItem(Start->NextItem,Start);
OrigLevel=Item->Level;
Dest->Level=5;
Dest->ItemNumber=Item->ItemNumber;
strcpy(Dest->Text,Item->Text);
for(;Dest->Level > OrigLevel;Dest->Level--)
{
AddItem(Dest);
RemItem(Dest);
}
AddItem(Dest);
AddItem(Dest->NextItem);
Item=(struct LineItem *)ClipStart->NextItem;
while(Item != NULL)
{
Dest=(struct LineItem *)InsertItem(Dest->NextItem,Dest);
Dest->Level=Item->Level;
Dest->ItemNumber=Item->ItemNumber;
strcpy(Dest->Text,Item->Text);
AddItem(Dest);
Item=(struct LineItem *)Item->NextItem;
}
TempY=CurY;
TempX=CurX;
PrintItemList(CurrentItem,CurY);
PlotCursor(TempX,TempY);
}